package com.heima.controller;

import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.VmTypeDTO;
import com.heima.pojo.entity.VmType;
import com.heima.result.PageResult;
import com.heima.service.VmTypeService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/vmType")
public class VmTypeController {
    @Autowired
    VmTypeService vmTypeService;

    /**
     * 设备搜索
     *
     * @param dto
     * @return
     */
    @GetMapping("/search")
    public PageResult<VmType> selectVmType(PageQueryDTO dto) {
        PageResult<VmType> vmType = vmTypeService.selectType(dto);
        return vmType;
    }

    /**
     * 新增设备类型
     */
    @PostMapping
    public boolean VmType(@RequestBody VmTypeDTO dto) {
        boolean result = vmTypeService.add(dto);
        return result;
    }

    /**
     * 修改设备类型
     */
    @PutMapping("/{typeId}")
    public boolean update(@PathVariable("typeId") Integer typeId, @RequestBody VmTypeDTO dto) {
        boolean result = vmTypeService.update(typeId, dto);
        return result;
    }
    /**
     * 删除设备类型
     */
    @DeleteMapping("/{typeId}")
    public boolean delete(@PathVariable("typeId") Integer typeId){
        boolean result = vmTypeService.delete(typeId);
        return result;
    }
}
